package com.suep.system.config;

import com.suep.system.exception.DataBaseNoDataException;
import com.suep.system.exception.RoleCheckException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/*全局异常处理器*/
@RestControllerAdvice
//+个Rest的好处就是自动使用JSON体，不然可能将一些错误响应识别成视图，导致404
public class GlobalExceptionHandler {

    //处理角色校验异常
    @ExceptionHandler(RoleCheckException.class)
    public BaseR handleRoleCheckException(RoleCheckException ex) {
        return new BaseR().forbidden(ex.getMessage());
    }
    @ExceptionHandler(DataBaseNoDataException.class)
    public BaseR handleDataBaseNoDataException(DataBaseNoDataException ex) {
        return new BaseR().ok("查询为空");
    }
}
